/*
 * KIMWONSORK@GMAIL.COM
 * COPYRIGHT CRAYONSOFT All rights reserved.
 * 2013오후 6:20:59
 * kws
 */

package com.crayon.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;

/**
 * com.crayon.widget.CheckableLinearLayout
 * @author kws
 *
 */
public class CheckableLinearLayout extends LinearLayout implements Checkable{
	private Checkable mCheckable;
	public CheckableLinearLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public boolean isChecked() {
		return mCheckable == null ? false : mCheckable.isChecked();
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();

		// Find Checkable child
		int childCount = getChildCount();
		for (int i = 0; i < childCount; ++i) {
			View v = getChildAt(i);
			if (v instanceof Checkable) {
				mCheckable = (Checkable) v;
				break;
			}
		}
	}

	@Override
	public void setChecked(boolean checked) {
		if(mCheckable != null)
			mCheckable.setChecked(checked);
	}

	@Override
	public void toggle() {
		if(mCheckable != null)
			mCheckable.toggle();
	}


}
